package com.xerland.tbootstrap.model;

/**
 * Fileame: com.xerland.tbootstrap.model
 * Desription:
 * Class and methods:
 * <p>
 * Author: Anson Chan
 * Copyright: 2016 Xerland Co. Ltd. All rights reserved.
 * Contact:    anson_chan@xerland.com
 * Deffield    updated: Updated
 */
public class PowerStateBean {

    public static final String ABNORMAL_TIME = "00-00-00 00:00:00";
    public static final String NULL_TIME = "";
    public static final int POWER_STATE_ON = 0;
    public static final int POWER_STATE_OFF = 1;
    public static final int POWER_STATE_ABNORMAL = 2;
    private int mMachID;
    private String mMachName;
    private String mPowerOnTime;
    private String mPowerOffTime;

    public PowerStateBean() {

    }

    public PowerStateBean(int mMachID, String mMachName, String mPowerOnTime, String mPowerOffTime) {
        this.mMachID = mMachID;
        this.mMachName = mMachName;
        this.mPowerOnTime = mPowerOnTime;
        this.mPowerOffTime = mPowerOffTime;
    }

    public int getMachID() {
        return mMachID;
    }

    public String getMachName() {
        return mMachName;
    }

    public String getPowerOnTime() {
        return mPowerOnTime;
    }

    public String getPowerOffTime() {
        return mPowerOffTime;
    }

    public PowerStateBean setMachID(int mMachID) {
        this.mMachID = mMachID;
        return this;
    }

    public PowerStateBean setMachName(String mMachName) {
        this.mMachName = mMachName;
        return this;
    }

    public PowerStateBean setPowerOnTime(String mPowerOnTimem) {
        this.mPowerOnTime = mPowerOnTimem;
        return this;
    }

    public PowerStateBean setPowerOffTime(String mPowerOffTime) {
        this.mPowerOffTime = mPowerOffTime;
        return this;
    }

    public int getState() {
        if ((this.mPowerOffTime == null || this.mPowerOffTime.isEmpty() || this.mPowerOffTime.equals("None"))
                && !this.mPowerOnTime.isEmpty()  && !this.mPowerOnTime.equals("None")) {
            return POWER_STATE_ON;
        }
        if (this.mPowerOffTime.equals(ABNORMAL_TIME)) {
            return POWER_STATE_ABNORMAL;
        }
        return POWER_STATE_OFF;
    }

    public String toJson() {
        return String.format("{\"mMachID\":%d, \"mMachName\":\"%s\", \"mPowerOnTime\":\"%s\", \"mPowerOffTime\":\"%s\"}",
                this.mMachID,
                this.mMachName,
                this.mPowerOnTime,
                this.mPowerOffTime);
    }
}
